Skip to content

Fix admin bulk result reporting across push providers - #830

Merged
JaeHyuckSa merged 2 commits into
django-commons:masterfrom
kocaemre:fix/admin-bulk-results-829
Nov 9, 2026
Merged

JaeHyuckSa merged 2 commits into
django-commons:masterfrom
kocaemre:fix/admin-bulk-results-829

Conversation

@kocaemre

@kocaemre kocaemre commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix #829: the admin bulk action now inspects every provider response rather than only the first item. An inactive-only selection no longer raises IndexError; WNS response strings and errors are reported instead of crashing; failures from later APNS groups and Web Push devices are no longer hidden. No provider send implementation changes. Existing single-send behavior and GCM admin action are retained.

Verification

RED, each before its corresponding fix (DJANGO_SETTINGS_MODULE=tests.settings):

  • python -m pytest tests/test_admin.py::WebPushDeviceAdminTestCase::test_bulk_action_with_only_inactive_devices_does_not_crash_or_claim_success -q --no-cov -p no:cacheprovider --tb=short → 1 failed, IndexError: list index out of range.
  • python -m pytest tests/test_admin.py::WNSDeviceAdminTestCase::test_bulk_action_reports_string_responses_without_crashing -q --no-cov -p no:cacheprovider --tb=short → 1 failed, AttributeError: 'str' object has no attribute 'items'.
  • python -m pytest tests/test_admin.py::WNSDeviceAdminTestCase::test_bulk_action_reports_wns_failure -q --no-cov -p no:cacheprovider --tb=short → 1 failed, uncaught WNSNotificationResponseError: HTTP 410.
  • python -m pytest tests/test_admin.py::APNSDeviceAdminTestCase::test_bulk_action_reports_failures_from_later_application_group -q --no-cov -p no:cacheprovider --tb=short → 1 failed, missing error-level message (KeyError: 'level').
  • python -m pytest tests/test_admin.py::WebPushDeviceAdminTestCase::test_bulk_action_reports_first_failed_webpush_with_later_success -q --no-cov -p no:cacheprovider --tb=short → 1 failed, KeyError: 'success'.

GREEN (Python 3.12, Django 5.2):

  • DJANGO_SETTINGS_MODULE=tests.settings PYTHONDONTWRITEBYTECODE=1 python -m pytest tests/test_admin.py -q --no-cov -p no:cacheprovider --tb=short → 8 passed.
  • Same environment, python -m pytest tests/ -q --no-cov -p no:cacheprovider --tb=short → 108 passed, 2 skipped, 45 subtests passed; one existing Web Push deprecation warning.
  • DJANGO_SETTINGS_MODULE=tests.settings_unique python -m pytest tests/tst_unique.py -q --no-cov -p no:cacheprovider --tb=short → 4 passed.
  • flake8 push_notifications/admin.py tests/test_admin.py and git diff --check → pass.

Tests use local Django database records and stub only outbound provider sends; no external push was sent. AI assistance: Hermes helped implement and run the regression tests; the contribution is submitted under the repository's MIT license.

Signed-off-by: Emre K <110906681+kocaemre@users.noreply.github.com>
@codecov

codecov Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.53%. Comparing base (455d2f3) to head (fe21fd4).

Files with missing lines Patch % Lines
push_notifications/admin.py 80.00% 5 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #830      +/-   ##
==========================================
+ Coverage   74.65%   78.53%   +3.88%     
==========================================
  Files          32       32              
  Lines        1365     1356       -9     
  Branches      226      220       -6     
==========================================
+ Hits         1019     1065      +46     
+ Misses        300      239      -61     
- Partials       46       52       +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JaeHyuckSa JaeHyuckSa left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Comment thread tests/test_admin.py
return {registration_ids[0]: status}

with mock.patch(
"push_notifications.apns_async.apns_send_bulk_message", side_effect=send_group

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apns_async imports aioapns, which the 3.7–3.9 jobs don't have, so this test fails there. It needs a skip like the other APNS tests.

Comment thread tests/test_admin.py Outdated
with mock.patch("push_notifications.webpush.webpush_send_message", side_effect=send):
admin.send_messages(HttpRequest(), WebPushDevice.objects.order_by("id"), bulk=True)

self.assertEqual(admin.message_user.call_args_list[0].kwargs["level"], messages.ERROR)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call_args.kwargs and .args are 3.8+, but CI still runs 3.7. call_args[1] and call_args[0] work everywhere (also lines 40, 53, 67, 68, 87 and 88).

Comment thread push_notifications/admin.py Outdated
success = 0
for batch in ret:
for response in batch:
# Some providers return a list per chunk.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing returns nested lists here, and ret only ever has one item in bulk mode, so one loop is enough. The comment looks unnecessary too, so feel free to drop it.

Signed-off-by: Emre K <110906681+kocaemre@users.noreply.github.com>
@kocaemre

kocaemre commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Follow-up fe21fd4 uses Python 3.7-compatible mock call tuples, skips the aioapns-only regression on Python <3.10, and removes the unused nested response-list handling. Previous CI RED: Python 3.8/3.9 APNS test failed; local GREEN: uvx --from tox --with tox-gh-actions tox -e py38-dj42 (97 passed, 3 skipped; unique-settings 4 passed), same with py39-dj42 (97 passed, 3 skipped; unique-settings 4 passed), Python 3.12 admin tests 8 passed / full tests 108 passed, 2 skipped, 45 subtests. Changed-file flake8 and git diff --check pass. Python 3.7 unavailable locally (uv has no CPython 3.7 build); awaiting CI/re-review. Repo-wide tox flake8 exits zero via --exit-zero despite existing unrelated diagnostics.

@JaeHyuckSa

Copy link
Copy Markdown
Member

Thanks for the review. Follow-up fe21fd4 uses Python 3.7-compatible mock call tuples, skips the aioapns-only regression on Python <3.10, and removes the unused nested response-list handling. Previous CI RED: Python 3.8/3.9 APNS test failed; local GREEN: uvx --from tox --with tox-gh-actions tox -e py38-dj42 (97 passed, 3 skipped; unique-settings 4 passed), same with py39-dj42 (97 passed, 3 skipped; unique-settings 4 passed), Python 3.12 admin tests 8 passed / full tests 108 passed, 2 skipped, 45 subtests. Changed-file flake8 and git diff --check pass. Python 3.7 unavailable locally (uv has no CPython 3.7 build); awaiting CI/re-review. Repo-wide tox flake8 exits zero via --exit-zero despite existing unrelated diagnostics.

Hey @kocaemre Using AI is fine, but please, review what it writes yourself before pushing or replying. If this keeps happening I'm not sure what we'd do about it, and honestly it makes me less keen to review these PRs.

@JaeHyuckSa
JaeHyuckSa merged commit dbe167c into django-commons:master Nov 9, 2026
13 checks passed
@50-Course

Copy link
Copy Markdown
Member

how did this pass review? that's a lot of crap out there in the description.

@JaeHyuckSa

JaeHyuckSa commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

how did this pass review? that's a lot of crap out there in the description.

@50-Course I agree, the description reads like unedited AI output. I've already asked the contributor to review what they submit.

I reviewed the code, requested changes, and those were addressed. CI passed, and I didn't find any remaining issues, so I merged it.

We'll probably see more PRs like this. We may need clearer guidelines and a way to deal with contributors who repeatedly ignore them. It might be worth looking at how other projects handle this, since I doubt we're the only ones facing this in the Django ecosystem.

I'd be interested to hear your thoughts on this, @50-Course.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Admin bulk test crashes or misreports results for Web Push, WNS and APNS

3 participants